//
//  YMMyDeviceMainListCell.m
//  YMMedical
//
//  Created by y s on 2023/7/26.
//

#import "YMMyDeviceMainListCell.h"
#import "YMAccountAuthorizationVC.h"

@interface YMMyDeviceMainListCell ()

@property (nonatomic, strong) UIView *vBg;
@property (nonatomic, strong) UIImageView *imgvIcon;
@property (nonatomic, strong) UILabel *lblName;
@property (nonatomic, strong) UILabel *lblNo;
@property (nonatomic, strong) UIButton *btnBinding;

@end

@implementation YMMyDeviceMainListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - UI methods
- (void)setUI{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    
    [self.contentView addSubview:self.vBg];
    [self.vBg addSubview:self.lblName];
    [self.vBg addSubview:self.imgvIcon];
    [self.vBg addSubview:self.lblNo];
    [self.vBg addSubview:self.btnBinding];

    [self.vBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo([SFitUtil fit:15]);
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.top.mas_equalTo(0);
    }];
    [self.imgvIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo([SFitUtil fit:15]);
        make.centerY.mas_equalTo(0);
        make.size.mas_equalTo([SFitUtil fitSize:68 height:68]);
    }];
    [self.lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.btnBinding.mas_left).offset([SFitUtil fit:-5]);
        make.top.mas_equalTo([SFitUtil fit:21]);
        make.left.equalTo(self.imgvIcon.mas_right).offset([SFitUtil fit:11]);
    }];
    [self.lblNo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.bottom.mas_equalTo([SFitUtil fit:-6]);
        make.left.equalTo(self.imgvIcon.mas_right).offset([SFitUtil fit:11]);
    }];
    [self.btnBinding mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.top.mas_equalTo([SFitUtil fit:15]);
        make.size.mas_equalTo([SFitUtil fitSize:95 height:27]);
    }];
}


#pragma mark - public methods
+ (CGFloat)getCellHeight{
    return [SFitUtil fit:98];
}
- (void)setDict:(NSDictionary *)dict{
    _dict = dict;
    NSString *name = KLanguage(@"device_txt");
    if (_index+1 < 10){
        name = [NSString stringWithFormat:@"%@0%ld",KLanguage(@"device_txt"),_index+1];
    }else{
        name = [NSString stringWithFormat:@"%@%ld",KLanguage(@"device_txt"),_index+1];
    }
    self.lblName.text = name;
    self.lblNo.text = [NSString stringWithFormat:@"%@：%@",KLanguage(@"device_sn"),[SDataUtil stringOf:dict[@"bhmohipntdlpc61m"]]];
    [_btnBinding setTitle:[NSString stringWithFormat:@"%@：%@",KLanguage(@"bind_account_txt"),[SDataUtil stringOf:dict[@"userNum"]]] forState:UIControlStateNormal];
}


- (void)bindingClickAction:(id)sender{
    YMAccountAuthorizationVC *vc = [[YMAccountAuthorizationVC alloc] init];
    vc.snCode = [SDataUtil stringOf:_dict[@"bhmohipntdlpc61m"] valid:@""];
    [SJumpUtil pushVC:vc animated:YES];
}

#pragma mark - setter and getter
- (UIView *)vBg{
    if (_vBg == nil){
        _vBg = [[UIView alloc] init];
        _vBg.backgroundColor = STheme.D9;
        _vBg.layer.cornerRadius = [SFitUtil fit:8];
        _vBg.clipsToBounds = YES;
    }
    return _vBg;
}
- (UIImageView *)imgvIcon{
    if (_imgvIcon == nil){
        _imgvIcon = [[UIImageView alloc] init];
        _imgvIcon.image = [UIImage imageNamed:@"mine_device_list_icon"];
    }
    return _imgvIcon;
}
- (UILabel *)lblName{
    if (_lblName == nil){
        _lblName = [[UILabel alloc] init];
        _lblName.textColor = STheme.D1;
        _lblName.font = [SFitUtil fitBoldFont:14];
    }
    return _lblName;
}
- (UILabel *)lblNo{
    if (_lblNo == nil){
        _lblNo = [[UILabel alloc] init];
        _lblNo.textColor = STheme.D1;
        _lblNo.font = [SFitUtil fitFont:12];
    }
    return _lblNo;
}
- (UIButton *)btnBinding{
    if (_btnBinding == nil){
        _btnBinding = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnBinding.layer.borderColor = [SUIUtil colorOf:0xCCCCCC].CGColor;
        _btnBinding.layer.borderWidth = [SFitUtil fitLine];
        _btnBinding.clipsToBounds = YES;
        _btnBinding.layer.cornerRadius = [SFitUtil fit:4];
        [_btnBinding setTitle:[NSString stringWithFormat:@"%@：",KLanguage(@"bind_account_txt")] forState:UIControlStateNormal];
        [_btnBinding setTitleColor:STheme.D12 forState:UIControlStateNormal];
        _btnBinding.titleLabel.font = [SFitUtil fitBoldFont:14];
        _btnBinding.titleLabel.adjustsFontSizeToFitWidth = YES;
        _btnBinding.titleLabel.minimumScaleFactor = 0.6;
        [_btnBinding addTarget:self action:@selector(bindingClickAction:) forControlEvents:UIControlEventTouchUpInside];
        _btnBinding.hidden = YES;
    }
    return _btnBinding;
}


@end
